const Router = require('@koa/router')
const glob = require('glob')
const { resolve } = require('path')
const { uploadExcel } = require('../controllers/upload')

const router = new Router()

router.get('/', async (ctx) => {
  await ctx.render('index')
})

router.post('/uploadExcel', uploadExcel) // 上传excel

glob
  .sync(resolve(__dirname, './', '**/*.js'))
  .filter((value) => value.indexOf('index.js') === -1)
  .map((modulePath) => {
    const moduleRouter = require(modulePath)
    router.use(moduleRouter.routes(), moduleRouter.allowedMethods())
  })

module.exports = router
